{include file="index/header"}
<body>
<div class="fly-panel fly-panel-user">
  <div class="tpt-admin">
    <div class="tpt-btn" style="float: left;margin: 0 20px 0 0">
      <a href="{:url('goods/add')}" class="layui-btn" style="float: left;margin-right: 5px;"><i class="layui-icon">&#xe608;</i> 添加商品</a>
      <button class="layui-btn" lay-submit lay-filter="delete_all"><i class="layui-icon">&#xe640;</i> 删除所有商品</button>
      <button class="layui-btn" lay-submit lay-filter="delete_all_category">按分类删除</button>
      <button class="layui-btn" lay-submit lay-filter="delete_all_time">按时间删除</button>
    </div>
    <div style="float: left;">
      <form class="layui-form" action="" method="get">
        <input placeholder="输入关键字" name="ks" value="<?php echo input('ks');?>" type="text" class="layui-input" style="float: left;margin-right: 10px;width: 240px;">
        <button class="layui-btn" style="float: left;" value="查询" type="submit">查询</button>
      </form>
    </div>
    <form class="layui-form" enctype="multipart/form-data" method="post">
      <table width="100%" {empty name="GoodsList"}style="margin-bottom: -17px;"{/empty}>
        <tr>
    	    <th width="3%" align="center"><input type="checkbox" name="checkAll" lay-filter="checkAll"></th>
    		  <th width="5%" align="center">商品ID</th>
          <th width="1%" align="center">主图</th>
          <th width="15%" align="center">商品标题</th>
          <th width="5%" align="center">在售价</th>
          <th width="5%" align="center">券后价</th>
          <th width="5%" align="center">优惠卷</th>   
          <th width="5%" align="center">佣金</th>
          <th width="5%" align="center">销量</th>                                 
      		<th width="5%" align="center">是否显示</th>
      		<th width="5%" align="center">是否置顶</th>
      		<th width="5%" align="center">是否精选</th>
      		<th width="5%" align="center">所属分类</th>
      		<th width="7%" align="center">添加时间</th>
          <th width="7%" align="center">基本操作</th>
        </tr>
        {empty name="GoodsList"}
        <tr style="height: 0px;border: none;">
          <td style="height: 0px;border: none;"></td>
          <td style="height: 0px;border: none;"></td>
          <td style="height: 0px;border: none;"><img src="__ROOT__/public/img/no_data.jpg" width="50" height="0"></td>
        </tr>        
        {else /}        
        {volist name="GoodsList" id="vo"}
  	    <tr>
    	    <td align="center"><input type="checkbox" name="ids[{$vo.id}]" lay-filter="checkOne" value="{$vo.id}"></td>
    		  <td align="center">{$vo.id}</td>
          <td align="center"><a target="_blank" href="{$vo.clickUrl}"><img src="{$vo.pic}" width="50"></a></td>
          <td style="padding:0 20px;"><a target="_blank" href="__INDEX__/dtl/{$vo.id}.html"><?php echo mb_substr(strip_tags(htmlspecialchars_decode($vo['title'])), 0,20, 'utf-8');?>...</a></td>
          <td align="center">{$vo.price}</td>    
          <td align="center">{$vo.couponPrice}</td>    
          <td align="center">{$vo.couponAmount}</td>
          <td align="center">{$vo.commission}</td>
          <td align="center">{$vo.volume}</td>                
      		<td align="center">
      		  <a change="{$vo.id}" onclick="changeshow(this);" {if condition="$vo['show'] eq 1"}class="layui-unselect layui-form-switch layui-form-onswitch"{else /}class="layui-unselect layui-form-switch"{/if}><em>显示</em><i></i>
      		  </a>
      		</td>
      		<td align="center">
      		  <a change="{$vo.id}" onclick="changesettop(this);" {if condition="$vo['settop'] eq 1"}class="layui-unselect layui-form-switch layui-form-onswitch"{else /}class="layui-unselect layui-form-switch"{/if}><em>顶置</em><i></i>
      		  </a>
      		</td>
      		<td align="center">
      		  <a change="{$vo.id}" onclick="changechoice(this);" {if condition="$vo['choice'] eq 1"}class="layui-unselect layui-form-switch layui-form-onswitch"{else /}class="layui-unselect layui-form-switch"{/if}>
      		    <em>精选</em><i></i>
      		  </a>
      		</td>
  		    <td align="center">
            <a target="_blank" href="__INDEX__/cat/{$vo.cid}.html">{$vo.name}</a>
          </td>
  		    <td align="center">{$vo.startTime|date="Y-m-d",###}</td>
          <td align="center">
            <a class="layui-btn layui-btn-mini layui-btn-warm" href="{:url('goods/edit',array('id'=>$vo['id']))}">修改</a> 
            <a class="layui-btn layui-btn-mini layui-btn-danger del_btn" member-id="{$vo.id}" title="删除" nickname="{$vo.title}">删除</a>
          </td>
        </tr>
        {/volist}
        {/empty}
      </table>
      <div class="layui-form-item">
        <div style="margin-top: 20px;float: left;">
          <button class="layui-btn" lay-submit lay-filter="delete">删除选中</button>
        </div>
        <div class="pages" style="float: right;">{$GoodsList->render()}</div>
      </div>
    </form>
  </div>
</div>
{include file="index_footer"}
<script type="text/javascript">
function changechoice(o){
  var change=$(o).attr("change"); 
  $.ajax({
    type:"post",
    dataType:"json",
      data:{change:change},
    url:"{:url('goods/changechoice')}", 
    success:function(data){
      if(data == 1){
        $(o).attr("class","layui-unselect layui-form-switch");
        }else{
        $(o).attr("class","layui-unselect layui-form-switch layui-form-onswitch");
        }
    }
  });
}
function changesettop(o){
  var change=$(o).attr("change");
  $.ajax({
    type:"post",
    dataType:"json",
      data:{change:change},
    url:"{:url('goods/changesettop')}",
    success:function(data){
      if(data == 1){
        $(o).attr("class","layui-unselect layui-form-switch");
        }else{
        $(o).attr("class","layui-unselect layui-form-switch layui-form-onswitch");
        }
    }
  });
}
function changeshow(o){
  var change=$(o).attr("change");
  $.ajax({
    type:"post",
    dataType:"json",
      data:{change:change},
    url:"{:url('goods/changeshow')}",
    success:function(data){
      if(data == 1){
        $(o).attr("class","layui-unselect layui-form-switch");
        }else{
        $(o).attr("class","layui-unselect layui-form-switch layui-form-onswitch");
        }
    }
  });
}
</script>
<script type="text/javascript">
layui.use(['form', 'laydate'], function(){
  var form = layui.form()
  ,layer = layui.layer
  ,laydate = layui.laydate
  ,jq = layui.jquery;

  jq('.del_btn').click(function(){
    var name = jq(this).attr('nickname');
    var id = jq(this).attr('member-id');
    layer.confirm('确定删除【'+name+'】?', function(index){
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
      jq.post('{:url("goods/dels")}',{'id':id},function(data){
        if(data.code == 200){
          layer.close(loading);
          layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
        }else{
          layer.close(loading);
          layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
        }
      });
    });   
  });
  
  form.on('checkbox(checkAll)', function(data){
    if(data.elem.checked){
      jq("input[type='checkbox']").prop('checked',true);
    }else{
      jq("input[type='checkbox']").prop('checked',false);
    }
    form.render('checkbox');
  });  

  form.on('checkbox(checkOne)', function(data){
    var is_check = true;
    if(data.elem.checked){
      jq("input[lay-filter='checkOne']").each(function(){
        if(!jq(this).prop('checked')){ is_check = false; }
      });
      if(is_check){
        jq("input[lay-filter='checkAll']").prop('checked',true);
      }
    }else{
      jq("input[lay-filter='checkAll']").prop('checked',false);
    } 
    form.render('checkbox');
  });

  form.on('submit(delete)', function(data){
    var is_check = false;
    jq("input[lay-filter='checkOne']").each(function(){
      if(jq(this).prop('checked')){ is_check = true; }
    });
    if(!is_check){
      layer.msg('请选择数据', {icon: 2,anim: 6,time: 1000});
      return false;
    }
    layer.confirm('确定批量删除?', function(index){
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
      var param = data.field;
      jq.post('{:url("goods/delss")}',param,function(data){
        if(data.code == 200){
          layer.close(loading);
          layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
        }else{
          layer.close(loading);
          layer.msg(data.msg, {icon: 2,anim: 6, time: 1000});
        }
      });
    });
    return false;
  });

  form.on('submit(delete_all)', function(data){
    layer.confirm('确定删除所有商品?', function(index){
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
      jq.post('{:url("goods/dels_all")}',function(data){
        if(data.code == 200){
          layer.close(loading);
          layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
        }else{
          layer.close(loading);
          layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
        }
      });
    });  
    return false;
  });

  form.on('submit(delete_all_category)', function(data){
    layer.confirm('<div class="layui-form-item" style="width: 300px;margin-top: 20px;"><label class="layui-form-label">入库分类：</label><div class="layui-input-block"><select id="layui-cid" name="cid" style="width: 150px;padding: 9px 15px;">{volist name="CategoryList" id="vo"}{if condition="$vo.open eq 1"}<option value="{$vo.id}">{$vo.name}</option>{/if}{/volist}</select></div></div>', function(index){
      var cid = jq("#layui-cid").val();
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
      jq.post('{:url("goods/dels_category")}',{cid:cid},function(data){
        if(data.code == 200){
          layer.close(loading);
          layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
        }else{
          layer.close(loading);
          layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
        }
      });
    });  
    return false;
  });

  form.on('submit(delete_all_time)', function(data){
    layer.confirm('<div class="layui-form-item"><div class="layui-inline"><label class="layui-form-label">开始时间：</label><div class="layui-input-inline"><input type="text" name="startTime" id="startTime" placeholder="yyyy-mm-dd" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this})"></div></div><div class="layui-inline"><label class="layui-form-label">结束时间：</label><div class="layui-input-inline"><input type="text" name="endTime" id="endTime" placeholder="yyyy-mm-dd" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this})"></div></div></div>', function(index){
      var startTime = jq("#startTime").val();
      var endTime = jq("#endTime").val();
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
      jq.post('{:url("goods/dels_time")}',{startTime:startTime,endTime:endTime},function(data){
        if(data.code == 200){
          layer.close(loading);
          layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
        }else{
          layer.close(loading);
          layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
        }
      });
    });  
    return false;
  });  
})
</script>
</body>
</html>